<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\BaseController;
use App\Models\AdvInvite;
use App\Models\Merchant;
use App\Models\ProducerAdv;
use Illuminate\Http\Request;

class AdvInviteController extends BaseController
{
    public function index(Request $request) {
        $input = $request->input();
        $title = $input['title'] ?? '';
        $producer_id = $request->input('producer_id');
        $daren_id = $request->input('daren_id');
        $search = ['start_at' => '', 'end_at' => '', 'status' => -1];
        $list = AdvInvite::apply($search, $input)->when($title, function ($q) use($title){
            $q->where('title', $title);
        })->when($producer_id, function ($q) use($producer_id){
            $q->where('producer_id', $producer_id);
        })->when($daren_id, function ($q) use($daren_id){
            $q->where('daren_id', $daren_id);
        })->orderBy("id", "desc")
            ->paginate(\request('per_page', 20));
        return $this->paginate($list);
    }

}

